package com.lg.concurrent.interrupt;

/**
 * sleep 方法会 判断interrupt 标志位
 *
 * 在为 true 的时候会
 * 抛出异常 InterruptedException并将标重置志位，修改为 false
 */
public class InterruptSleep {

    static class  SleepThread extends Thread{

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                System.out.println(i);
//                Thread.sleep(10);
            }

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) throws InterruptedException {
        SleepThread sleepThread = new SleepThread();
        sleepThread.start();
        sleepThread.interrupt();
        System.out.println("sleepThread-->" +sleepThread.isInterrupted());
        System.out.println("main run over ,wait join");

        sleepThread.join();
        Thread.sleep(10);

        System.out.println("sleepThread-->" +sleepThread.isInterrupted());
    }
}
